	<!DOCTYPE html>
	<html lang="zxx" class="no-js">
	<head>
		<!-- Mobile Specific Meta -->
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<!-- Favicon-->
		<link rel="shortcut icon" href="img/fav.png">
		<!-- Author Meta -->
		<meta name="author" content="colorlib">
		<!-- Meta Description -->
		<meta name="description" content="">
		<!-- Meta Keyword -->
		<meta name="keywords" content="">
		<!-- meta character set -->
		<meta charset="UTF-8">
		<!-- Site Title -->
		<title>Taxi</title>

		<link href="https://fonts.googleapis.com/css?family=Poppins:100,200,400,300,500,600,700" rel="stylesheet"> 
			<!--
			CSS
			============================================= -->
			<link rel="stylesheet" href="css/linearicons.css">
			<link rel="stylesheet" href="css/font-awesome.min.css">
			<link rel="stylesheet" href="css/bootstrap.css">
			<link rel="stylesheet" href="css/magnific-popup.css">
			<link rel="stylesheet" href="css/nice-select.css">							
			<link rel="stylesheet" href="css/animate.min.css">
			<link rel="stylesheet" href="css/jquery-ui.css">			
			<link rel="stylesheet" href="css/main.css">
			
			<?php
				session_start();
                $user = 'root';
                $pass = '';
                $dbh = new PDO('mysql:host=localhost;dbname=taxi', $user, $pass);
				
  $db_host = 'localhost';
  $db_user = 'root';
  $db_pass = '';
  // Подключение к базе данных MySQL.
  @$on_link = mysqli_connect($db_host, $db_user, $db_pass);
  if (!$on_link) {
  echo "Ошибка соединения с сервером MySQL!";
  exit;
  }
// изменение набора символов на utf8
  mysqli_set_charset($on_link, "utf8");
// Выбираем БД для работы в MySQL.
	$db_base_ref = 'taxi';
  @$db_select = mysqli_select_db ($on_link, $db_base_ref);
    if (!$db_select) {
    echo "Не удалось выбрать БД MySQL.";
    exit;
    }
?>
			
		</head>
		<body>	
			  <header id="header">
		  		<div class="header-top">
				</div>
			    <div class="container main-menu">
			    	<div class="row align-items-center justify-content-between d-flex">
			    		<a href="index.php"><img src="img/logo.png" alt="" title="" /></a>		
						<nav id="nav-menu-container">
							<ul class="nav-menu">
							  <li class="menu-active"><a href="index.php">Главная</a></li>

							  <li><a href="auto.php">Наш автопарк</a></li>						  			          	          
							  <li><a href="contact.php">Контакты</a></li>
							  <?php if(isset($_SESSION['logged_user'])) : ?>
							  <li><a href="lk.php">Личный кабинет</a></li>
							  <?php else : ?>
							  <li><a href="login.php">Войти</a></li>
							  <?php endif; ?>
							</ul>
						</nav><!-- #nav-menu-container -->		
			    	</div>
			    </div>
			  </header><!-- #header -->

			<!-- start banner Area -->
			<section class="banner-area relative" id="home">
				<div class="overlay overlay-bg"></div>	
				<div class="container">
					<div class="row fullscreen d-flex align-items-center justify-content-between">
						<div class="banner-content col-lg-6 col-md-6 ">
							<h6 class="text-white ">Нуждаешься в такси? Просто позвони</h6>
							<h1 class="text-uppercase">
								500-600				
							</h1>
							<p class="pt-10 pb-10 text-white">
								Независимо от того, любите ли вы отдых в городе или продолжительный отдых на солнце, вы всегда можете улучшить свои впечатления от путешествия в нашем такси.
							</p>

						</div>
						<div class="col-lg-4  col-md-6 header-right">
							<h4 class="pb-30">Закажи такси!</h4>
							<form class="form" method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
							    <div class="from-group">
							    	<input class="form-control txt-field" type="text" name="name_zakaz" placeholder="Ваше имя"  onfocus="this.placeholder = ''" onblur="this.placeholder = 'Ваше имя'">
							    	<input class="form-control txt-field" type="email" name="email_zakaz" placeholder="Email" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Email'">
							    	<input class="form-control txt-field" type="tel" name="phone_zakaz" placeholder="Номер телефона" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Номер телефона'">
									<?php
									$sql = "SELECT * FROM `auto`";
									$result_select = mysqli_query($on_link, $sql);
  
									echo "<select class='form-control txt-field' name = 'auto_zakaz'>";
									echo "<option data-display='Выберите авто'>Авто:</option>";
									while($object = mysqli_fetch_object($result_select)){
										echo "<option class='text-white' value = '$object->name_car' > $object->name_car</option>";}
										echo "</select>";
									?>	
									<input class="form-control txt-field" type="text" name="ot_zalaz" placeholder="От куда"  onfocus="this.placeholder = ''" onblur="this.placeholder = 'От куда'">
									<input class="form-control txt-field" type="text" name="kuda_zakaz" placeholder="Куда"  onfocus="this.placeholder = ''" onblur="this.placeholder = 'Куда'">
									<input class="form-control txt-field" type="date" name="date_zakaz" placeholder="Дата" min="<?php echo date('Y-m-d'); ?>"  onfocus="this.placeholder = ''" onblur="this.placeholder = 'Дата'">
									<input class="form-control txt-field" type="time" name="time_zakaz" placeholder="Время"  onfocus="this.placeholder = ''" onblur="this.placeholder = 'Время'">
							    </div>													    						    
							    <div class="form-group">

							            <button class="btn btn-default btn-lg btn-block text-center text-uppercase">Сделать заказ</button>

							    </div>
								
								<?php
$errors = array();


if ($_SERVER["REQUEST_METHOD"] == "POST") {
	if(empty($_POST["name_zakaz"])){

		$errors[] = "Введите имя!";
	}
	if(empty($_POST["email_zakaz"])){

		$errors[] = "Введите email!";
	}
	if(empty($_POST["phone_zakaz"])){

		$errors[] = "Введите телефон!";
	}
	if(empty($_POST["auto_zakaz"])){

		$errors[] = "Выберите авто!";
	}
	if(empty($_POST["ot_zalaz"])){

		$errors[] = "Введите место!";
	}
	if(empty($_POST["kuda_zakaz"])){

		$errors[] = "Введите место!";
	}
	if(empty($_POST["date_zakaz"])){

		$errors[] = "Выберите дату!";
	}
	if(empty($_POST["time_zakaz"])){

		$errors[] = "Выберите время!";
	}
	
	if (mb_strlen($_POST['phone_zakaz']) < 10 || mb_strlen($_POST['phone_zakaz']) > 11){
	    
	    $errors[] = "Недопустимая длина номера!";

    }
	
	if(empty($errors)) {
	
    $name_zakaz = test_input($_POST["name_zakaz"]);
    $email_zakaz = test_input($_POST["email_zakaz"]);
    $phone_zakaz = test_input($_POST["phone_zakaz"]);
	$auto_zakaz = test_input($_POST["auto_zakaz"]);
	$ot_zalaz = test_input($_POST["ot_zalaz"]);
	$kuda_zakaz = test_input($_POST["kuda_zakaz"]);
	$date_zakaz = test_input($_POST["date_zakaz"]);
	$time_zakaz = test_input($_POST["time_zakaz"]);
	
	$sth = $dbh->prepare(
    "INSERT INTO 
                `zakazi`(`name_zakaz`, `email_zakaz`, `phone_zakaz`, `auto_zakaz`, `ot_zalaz`, `kuda_zakaz`, `date_zakaz`, `time_zakaz`) 
            VALUES 
                (:name_zakaz, :email_zakaz, :phone_zakaz, :auto_zakaz, :ot_zalaz, :kuda_zakaz, :date_zakaz, :time_zakaz)
            ");
	$sth->execute(array('name_zakaz' => $name_zakaz,
						'email_zakaz' => $email_zakaz,
						'phone_zakaz' => $phone_zakaz,
						'auto_zakaz' => $auto_zakaz,
						'ot_zalaz' => $ot_zalaz,
						'kuda_zakaz' => $kuda_zakaz,
						'date_zakaz' => $date_zakaz,
						'time_zakaz' => $time_zakaz));
						
		} else {
                // array_shift() извлекает первое значение массива array и возвращает его, сокращая размер array на один элемент. 
		echo '<center>';			
		echo '<div class="font-weight-bold" style="color: red; ">' . array_shift($errors). '</div><hr>';
		echo '</center>';
	}					

}
	function test_input($data) {
		$data = trim($data);
		$data = stripslashes($data);
		$data = htmlspecialchars($data);
		return $data;
	}

?>	
								
								
							</form>
						</div>											
					</div>
				</div>					
			</section>
			<!-- End banner Area -->		


			<!-- Start home-about Area -->
			<section class="home-about-area section-gap">
					
			</section>
			<!-- End home-about Area -->
			
			<!-- Start services Area -->
			<section class="services-area pb-120">
				<div class="container">
					<div class="row section-title">
						<h1>Какие услуги мы предлагаем нашим клиентам</h1>
						
					</div>
					<div class="row">
						<div class="col-lg-4 single-service">
							<span class="lnr lnr-car"></span>
							<a href="#"><h4>Служба такси</h4></a>
							<p>
								На такси и днём и ночью - путь быстрее и короче!
							</p>
						</div>
						<div class="col-lg-4 single-service">
							
						</div>
						<div class="col-lg-4 single-service">
							<span class="lnr lnr-bus"></span>
							<a href="#"><h4>Автобусы</h4></a>
							<p>
								Хватит, ноги берегите - и таксистам позвоните!
							</p>
						</div>												
					</div>	
				</div>	
			</section>
			<!-- End services Area -->
			
			<!-- Start image-gallery Area -->
			<section class="image-gallery-area section-gap">
				<div class="container">
					<div class="row section-title">
						<h1>Галерея изображений, которыми мы хотели бы поделиться</h1>
						
					</div>					
					<div class="row">
						<div class="col-lg-4 single-gallery">
							<a href="img/g1.jpg" class="img-gal"><img class="img-fluid" src="img/g1.jpg" alt=""></a>
							<a href="img/g4.jpg" class="img-gal"><img class="img-fluid" src="img/g4.jpg" alt=""></a>
						</div>	
						<div class="col-lg-4 single-gallery">
							<a href="img/g2.jpg" class="img-gal"><img class="img-fluid" src="img/g2.jpg" alt=""></a>
							<a href="img/g5.jpg" class="img-gal"><img class="img-fluid" src="img/g5.jpg" alt=""></a>						
						</div>	
						<div class="col-lg-4 single-gallery">
							<a href="img/g3.jpg" class="img-gal"><img class="img-fluid" src="img/g3.jpg" alt=""></a>
							<a href="img/g6.jpg" class="img-gal"><img class="img-fluid" src="img/g6.jpg" alt=""></a>
						</div>				
					</div>
				</div>	
			</section>
			<!-- End image-gallery Area -->
			
			<!-- Start reviews Area -->
			
			<!-- End reviews Area -->
							
			<!-- Start home-calltoaction Area -->
			<section class="home-calltoaction-area relative">
				<div class="container">
					<div class="overlay overlay-bg"></div>
					<div class="row align-items-center section-gap">
						<div class="col-lg-8">
							<h1>Служба поддержки</h1>
							
						</div>
						<div class="col-lg-4 btn-left">
							<a href="#" class="primary-btn">Позвонить</a>
						</div>
					</div>
				</div>	
			</section>
			<!-- End home-calltoaction Area -->
			
			<!-- Start latest-blog Area -->
			
			<!-- End latest-blog Area -->
			
			<!-- start footer Area -->		
			<footer class="footer-area dunku">
				
							<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
<div align="center"> Copyright &copy;<script>document.write(new Date().getFullYear());</script> All rights reserved </div>
<!-- Link back to Colorlib can't be removed. Template is licensed under CC BY 3.0. -->
						</p>											
				<img class="footer-bottom" src="img/footer-bottom.png" alt="">
			</footer>	
			<!-- End footer Area -->	

			<script src="js/vendor/jquery-2.2.4.min.js"></script>
			<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
			<script src="js/vendor/bootstrap.min.js"></script>			
			<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBhOdIF3Y9382fqJYt5I_sswSrEw5eihAA"></script>
  			<script src="js/easing.min.js"></script>			
			<script src="js/hoverIntent.js"></script>
			<script src="js/superfish.min.js"></script>	
			<script src="js/jquery.ajaxchimp.min.js"></script>
			<script src="js/jquery.magnific-popup.min.js"></script>	
 			<script src="js/jquery-ui.js"></script>								
			<script src="js/jquery.nice-select.min.js"></script>							
			<script src="js/mail-script.js"></script>	
			<script src="js/main.js"></script>	
		</body>
	</html>